﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using TomNet.App.Core.Contracts;
using TomNet.App.Model.DB;
using TomNet.App.Model.DTO;
using TomNet.AspNetCore.Data;
using TomNet.SqlSugarCore.Entity;
using TomNet.Security.Claims;
using System.Security.Claims;
using TomNet.App.Model.DB.Identity;

namespace TomNet.App.Web.Controllers
{
    [Authorize]
    [Description("奖励订单收益管理")]
    public class UserRewardBusinessIncomeRunningsController : Controller
    {
        private readonly IUserRewardBusinessIncomeRunningsContract _userRewardBusinessIncomeRunningsContract;        
        private readonly IUnitOfWork _unitOfWork;
        public UserRewardBusinessIncomeRunningsController(IUserRewardBusinessIncomeRunningsContract userRewardBusinessIncomeRunningsContract,            
            IUnitOfWork unitOfWork)
        {
            _userRewardBusinessIncomeRunningsContract = userRewardBusinessIncomeRunningsContract;
            _unitOfWork = unitOfWork;
        }
        [Description("奖励订单收益列表")]
        [HttpGet]
        public IActionResult UserRewardBusinessIncomeRunningList()
        {
            return View();
        }
        [Description("奖励订单收益列表")]
        [HttpPost]
        public IActionResult UserRewardBusinessIncomeRunningList(int page = 1, int limit = 20)
        {
            var query = _userRewardBusinessIncomeRunningsContract.UnitOfWork.DbContext.Queryable<UserRewardBusinessIncomeRunnings, Business>((ub, b)
                   => ub.UserRewardBusinessID == b.Id)
                //.Where((ub, b, u) => r.Id == intType)
                .OrderBy((ub, b) => ub.Id, OrderByType.Desc)
               .Select((ub, b) => new UserRewardBusinessIncomeRunningsDto
               {
                   UserRewardBusinessID = b.Id,
                   CreatedTime = ub.CreatedTime,
                   RunTime = ub.RunTime,
                   Amount = ub.Amount,
                   ElectricCharge = ub.ElectricCharge,
               });
            int total = 0;
            var list = query.ToPageList(page, limit, ref total);
            var result = new LayuiPageResult<UserRewardBusinessIncomeRunningsDto>
            {
                Code = 0,
                Msg = "Success",
                Count = total,
                Data = list.ToArray()
            };
            return Json(result);
        }        
    }
}